home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / comm / mail / YAM23src.lha / Source / gen_gates.pl < prev    next >
Perl Script  |  2001-05-02  |  1KB  |  71 lines

  1. #!/bin/perl
  2. #
  3. # gen_gates.pl - Copyright 2000 by E. Lesueur
  4. #
  5. # This program is in the public domain.
  6. #
  7. # Generates MorphOS gates for YAM.
  8.  
  9. undef $/;
  10.  
  11. die "No source" if not $file=@ARGV[0];
  12.  
  13. open(INP,"<$file") || die "Can't open \"".$file."\"\n";
  14. $source = <INP>;
  15.  
  16. # strip comments
  17. $source =~ s%/\*.*?\*/%%sg;
  18.  
  19. $source =~ s/\n([^\n]*?)SAVEDS\s*(ASM)*\s*([^\n]*?)\s*\n{\s*\n(.*?)\n}\s*\n/cv_func($1.$3,$4)/egs;
  20.  
  21. close <INP>;
  22.  
  23.  
  24. sub cv_func {
  25.     local ($decl, $body) = @_;
  26.     local ($ret_type, $name, $params, $trap, $ret);
  27.     local ($args, $reg, $type, $param, $params);
  28.  
  29.     if ($decl =~ /^(.*?)(\w+)\((.*)\)$/) {
  30.     $ret_type = $1;
  31.     $name = $2;
  32.     $params = $3;
  33.     } else {
  34.     die "Strange declaration :\"".$decl."\"\n";
  35.     }
  36.  
  37.     if ($ret_type =~ /^\s*void\s*$/) {
  38.     $trap = "TRAP_LIBNR";
  39.     $ret = "";
  40.     } else {
  41.     $trap = "TRAP_LIB";
  42.     $ret = "return ";
  43.     }
  44.  
  45.     $args = "";
  46.     while ($params =~ /^\s*REG\((\w\w),\s*(.*?)\s*(\w+)\)(,(.*)$|$)/) {
  47.     $reg = $1;
  48.     $type = $2;
  49.     $param = $3;
  50.     $params = $5;
  51.     if (length($args) != 0) {
  52.         $args = $args.", ";
  53.     }
  54.     $args = $args."(".$type.")REG_".uc($reg);
  55.     if ($type =~ /struct\s+(\w+)/) {
  56.         print "struct $1;\n";
  57.     }
  58.     }
  59.  
  60.     $decl =~ s/REG\(\w\w,(.*?)\)\s*/$1/g;
  61.  
  62.     print "$decl;\n"
  63.        ."static $ret_type Trampoline_$name(void)\n{\n"
  64.        ."   $ret$name($args);\n}\n"
  65.        ."const struct EmulLibEntry Gate_$name"
  66.        ." = { $trap, 0, (void(*)())Trampoline_$name };\n\n";
  67.  
  68.     return "";
  69. }
  70.  
  71.